use captcha_rs::CaptchaBuilder;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Captcha {
    pub code: Option<String>,
    pub data: Option<String>,
}

impl Captcha {
    pub fn new() -> Self {
        let captcha = CaptchaBuilder::new()
            .length(6)
            .width(130)
            .height(40)
            .dark_mode(false)
            .complexity(1) // min: 1, max: 10
            .compression(40) // min: 1, max: 99
            .build();
        Self {
            code: captcha.text.to_lowercase().into(),
            data: captcha.to_base64().to_string().into(),
        }
    }
}

#[cfg(test)]
mod test {
    use crate::plugin::captcha::Captcha;

    #[test]
    fn get_captcha() {
        let result = Captcha::new();
        println!("{:?}", result);
    }
}
